﻿using System;
using System.Text;

namespace MinecraftEnchantCalculator.Converters;

public static class RomanNumeralConverter
{
  private static readonly (int Value, string Symbol)[] _Map = {
    (1000, "M"),
    (900, "CM"),
    (500, "D"),
    (400, "CD"),
    (100, "C"),
    (90, "XC"),
    (50, "L"),
    (40, "XL"),
    (10, "X"),
    (9, "IX"),
    (5, "V"),
    (4, "IV"),
    (1, "I")
  };

  public static string ToRoman(int number)
  {
    if (number is <= 0 or > 3999)
      throw new ArgumentOutOfRangeException(nameof(number), "只能转换 1 到 3999 之间的数字。");

    var result = new StringBuilder();

    foreach (var (value, symbol) in _Map)
      while (number >= value) {
        result.Append(symbol);
        number -= value;
      }

    return result.ToString();
  }
}